﻿using System;

namespace DevelopersTestPad.Worksheets.DotNet.Interaction
{
    /// <summary>
    /// Manages scripts.
    /// </summary>
    internal sealed class ScriptManager : IDisposable
    {
        /// <summary>
        /// Gets a script wrapper.
        /// </summary>
        /// <param name="worksheetType">The worksheet type.</param>
        /// <param name="codeLines">The code lines.</param>
        /// <param name="wasNewCreated">Was the new script wrapper created.</param>
        internal ScriptWrapper GetScript(WorksheetType worksheetType, string codeLines, out bool wasNewCreated)
        {
            lock (this)
            {
                ScriptWrapper script = new ScriptWrapper(worksheetType, codeLines);
                wasNewCreated = true;

                return script;
            }
        }

        /// <summary>
        /// Releases the script.
        /// </summary>
        internal void Release(ScriptWrapper script)
        {
            lock (this)
            {
                script.Dispose();
            }
        }

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        public void Dispose()
        {
        }
    }
}
